<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<!--样式表开始-->
		<link type="text/css" rel="stylesheet" href="css/demo.css">
		<!--<link type="text/css" rel="stylesheet" href="css/style1.css">-->
		<!--样式表结束-->
		<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>

		<!--标准mui.css-->
		<link rel="stylesheet" href="css/mui.min.css">
		<!--弹出下拉菜单-->
		<link rel="stylesheet" type="text/css" href="css/menu.css" />

		<link rel="stylesheet" type="text/css" href="css/icons-extra.css" />
		<style>
			.r {
				border-bottom: 8px solid #eee;
				border-left: 8px solid transparent;
				border-right: 8px solid transparent;
				width: 1px;
				margin-top: 5px;
				margin-left: 10px
			}
			
			.c-icon {
				width: 20px;
				float: right;
			}
			
			.cmt-wrap {
				width: 100%;
				background-color: #eee
			}
			
			.like {
				color: #576b95;
				padding: 5px 5px 3px 12px
			}
			
			.like img {
				width: 12px;
				padding-right: 5px
			}
			
			.cmt-list {
				padding: 5px 12px;
				color: #454545
			}
			
			.cmt-list p {
				padding-top: 3px
			}
			
			.cmt-list span {
				color: #3b5384
			}
			
			.one {
				color: #C7254E;
			}
		</style>
	</head>

	<body>
		<!--右上角弹出菜单-->
		<div id="topPopover" class="mui-popover">
			<div class="mui-popover-arrow"></div>
			<div class="mui-scroll-wrapper">
				<div class="mui-scroll">
					<ul class="mui-table-view">
						<li class="mui-table-view-cell">
							<a href="information.html">图文信息</a>
						</li>
						<li class="mui-table-view-cell">
							<a href="noticeList.html" id="aa">公告信息</a>
						</li>

					</ul>
				</div>
			</div>
		</div>
		</div>

		<header class="mui-bar mui-bar-nav">
			<a class="mui-pull-right" id="open"></a>
			<a id="menu" class="mui-icon mui-icon-plusempty mui-pull-right" href="#topPopover"></a>
			<h1 class="mui-title">发现</h1>
		</header>
		<!--
            	描述：消息  
           -->
		<div class="mui-content">
			<div id="pullrefresh" class="mui-car">
				<div class="mui-card-header mui-card-media" id="share">

				</div>
			</div>
		</div>
		</div>

		</div>

	</body>
	<script src="js/mui.min.js"></script>
	<script src="js/mui.zoom.js"></script>
	<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
	<script type="text/javascript" charset="UTF-8">
		mui.init();
		var createBy = localStorage.getItem("employeeid");
		var loginName = localStorage.getItem("loginName");

		//预加载
		mui.plusReady(function() {
			checkWho();
			
		});

		//下拉刷新
		mui.init({
			pullRefresh: {
				container: '#pullrefresh',
				down: {
					style: 'circle',
					auto: true,
					callback: share111
				},
				up: {
					auto: true,
					contentrefresh: '正在加载...',
					ccallback: share111
				}
			}
		});

		//时间的格式转化
		function mmtime(time) {
			var newDate = new Date(time);
			var year = newDate.getFullYear();
			var month = (newDate.getMonth() + 1) < 10 ? "0" + (newDate.getMonth() + 1) : newDate.getMonth() + 1;
			var day = newDate.getDate() < 10 ? "0" + newDate.getDate() : newDate.getDate();
			var hours = newDate.getHours() < 10 ? "0" + newDate.getHours() : newDate.getHours();
			var minuts = newDate.getMinutes() < 10 ? "0" + newDate.getMinutes() : newDate.getMinutes();
			var seconds = newDate.getSeconds() < 10 ? "0" + newDate.getSeconds() : newDate.getSeconds();
			time = year + "-" + month + "-" + day + " " + hours + ":" + minuts + ":" + seconds;
			return time;
		}

		//图文信息列表	 
		function share111() {

			var network = true;
			if(mui.os.plus) {
				mui.plusReady(function() {
					if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
						network = false;
					}
				});
			}
			if(network) {
				mui.ajax({
					url: 'http://113.71.26.27:8080/tpl/function/findemployee',
					async: true,
					type: 'post',
					timeout: 2000,
					data: {
						createBy: createBy
					},
					success: function(data) {
						if(data.companyId != null) {
							mui.ajax({
								type: "post",
								url: "http://113.71.26.27:8080/tpl/function/findcomment",
								async: true,
								data: {},
								dataType: "json",
								timeout: 2000,
								crossDomain: true,
								success: function(data) {
									var shareData = '';
									var cc = "";
									//console.log('响应成功！');
									for(var i = 0; i < data.length; i++) {
										//console.log("data[i].describe1：" + data[i].describe1);
										
										
										shareData += "<div class='mui-media-body'>"
										shareData += "<img src='http://113.71.26.27:8080/tpl/public/uploadImage/peopleLogo/" + data[i].employee.imgUrl + "' style='width:45px;height:45px;position:relative;top:0px;left:-50px;'/>"
										shareData += "<label class='mui-card-l' style='position:relative;top:-18px;left:-48px;'>" + data[i].employee.name + "</label>"
										shareData += "<div class='mui-card-content'>"
										
										
										shareData += "<a id=shareId" + i + " style='color: #333;'>" + data[i].describe1 + "</a><br/>"
										shareData += "<div><img src='http://113.71.26.27:8080/tpl/public/uploadImage/share/" + data[i].photo + "' style='width: 265px; height: 300px;'/>"
										shareData += "<br/>"
										if(data[i].employee.id==createBy){
											shareData += "<a class='left' onclick=mevent(" + data[i].id + ")>删除</a>"
										}
										shareData += "<img class='c-icon ' src='images/c.png' onclick=move(" + i + ")></div>" +
											"<div id=kk" + i + " style='display:none'><div class='mui-input-row'><input style='width:195px;height:35px;' id=ff" + i + " type='text'/><button style='height:35px;' id=fff" + i + " onclick=out(" + i + "," + data[i].id + ")   disabled='true'>发送</button></div></div>"
										//评论框 
										shareData += "<div class='cmt-wrap'><div class='cmt-list'>";
										cc = data[i];
										for(var j = 0; j < cc.comment.length; j++) {
											if(cc.comment[j].toemployee == null) {
												shareData += "<div onclick=move1(" + i + "," + j + "," + cc.comment[j].fromemployee.id + ")><p><span>" + cc.comment[j].fromemployee.name + "<span>:" + cc.comment[j].content + "</p></div>";
											} else {
												shareData += "<div onclick=move1(" + i + "," + j + "," + cc.comment[j].fromemployee.id + ")><p><span>" + cc.comment[j].fromemployee.name + "回复" + cc.comment[j].toemployee.name + "<span>:" + cc.comment[j].content + "</p></div>";
											}
											shareData += "<div id=k" + i + "k" + j + " style='display:none'><div class='mui-input-row'><input style='width:218px;height:35px;' id=f" + i + "f" + j + " type='text' placeholder=" + '回复' + cc.comment[j].fromemployee.name + ":" + "> <button style='height:35px;' id=f" + i + "ff" + j + " onclick=out1(" + i + "," + j + "," + cc.id + "," + cc.comment[j].fromemployee.id + ")  disabled='true'>发送</button></div></div>";

										}
										shareData += "</div>"
										shareData += "</div>"
										shareData += "</div>"
										shareData += "</div>"
										shareData += "<hr style='height:0.5px;border:none;border-top:0.1px solid #DBDBDB;' />"

									}
									document.getElementById("share").innerHTML = shareData;
									mui('#pullrefresh').pullRefresh().endPulldownToRefresh();

								},
								error: function(xhr, type, errorThrown) {
									plus.nativeUI.toast(errorThrown);
								}
							});

						}

					}
				});

			} else {
				mui.toast("当前网络不给力，请稍后再试...");
			}
		}

		//交互:图文信息数据删除
		function mevent(id) {
			var network = true;
			if(mui.os.plus) {
				mui.plusReady(function() {
					if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
						network = false;
					}
				});
			}
			if(network) {
				console.log('网络正常,正在发送请求...');
				var btnArray = ['否', '是'];
				mui.confirm('是否删除所选分享资源吗？', '', btnArray, function(e) {
					if(e.index == 1) {
						mui.toast("删除成功");
						mdelete(id);

					} else {
						mui.toast("删除失败");
					}
				});
			} else {
				mui.toast("当前网络不给力，请稍后再试...");
			}
		}
		//ajax删除
		function mdelete(id) {
			var network = true;
			if(mui.os.plus) {
				mui.plusReady(function() {
					if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
						network = false;
					}
				});
			}
			if(network) {

				mui.ajax({
					url: 'http://113.71.26.27:8080/tpl/share1/deleteShare?id=' + id,
					async: true,
					type: 'get',
					success: function() {
						window.location.href = "findoutupdate2.html"; //打开findoutupdate页面，并刷新这个页面
					},
					error: function(xhr, type, errorThrown) {
						plus.nativeUI.toast(errorThrown);
					}
				});
			} else {
				mui.toast("当前网络不给力，请稍后再试...");
			}
		}

		//评论模块
		function move(i) {
			document.getElementById("kk" + i).style.display = "";
			//对输入框进行监听
			var cinput = document.getElementById("ff" + i); //输入框
			var cbutton = document.getElementById("fff" + i); //button
			cinput.addEventListener('input', function() {
				cbutton.disabled = false;
				if(cinput.value.length == 0) {
					cbutton.disabled = true;
				}
			});
			//自动获取焦点
			cinput.focus();
			//失去焦点
			cinput.addEventListener('blur', function() {
				setTimeout(function() {
					document.getElementById("kk" + i).style.display = "none";
				}, 200);
			});
		}

		function out(i, topic_id, to_uid) {
			document.getElementById("kk" + i).style.display = "none";
			//文本内容
			var content = document.getElementById("ff" + i).value;
			maddscomment(topic_id, content);
		}

		//回复模块
		function move1(i, j, from_uid) {
			var str = "k" + i + "k" + j;
			//判断是否本人回复本人
			if(createBy != from_uid) {
				document.getElementById(str).style.display = "";
				//对输入框进行监听
				var cinput = document.getElementById("f" + i + "f" + j); //输入框
				var cbutton = document.getElementById("f" + i + "ff" + j); //button
				cinput.addEventListener('input', function() {
					cbutton.disabled = false;
					if(cinput.value.length == 0) {
						cbutton.disabled = true;
					}
				});
				//自动获取焦点
				cinput.focus();
				//失去焦点
				cinput.addEventListener('blur', function() {
					setTimeout(function() {
						document.getElementById(str).style.display = "none";
					}, 200);
				});
			}
		}

		function out1(i, j, topic_id, from_uid) {
			var str = "k" + i + "k" + j;
			document.getElementById(str).style.display = "none";
			//文本内容
			var content = document.getElementById("f" + i + "f" + j).value;
			maddcomment(topic_id, from_uid, content);

		}
		//评论ajax
		function maddscomment(topic_id, content) {
			var from_id = createBy;

			mui.ajax({
				url: 'http://113.71.26.27:8080/tpl/function/insertcomment',
				async: true,
				type: 'post',
				data: {
					topic_id: topic_id,
					from_id: from_id,
					content: content
				},
				success: function(data) {
					share111(); 
				}
			});
		}
		//回复ajax
		function maddcomment(topic_id, to_id, content) {
			var from_id = createBy;
			mui.ajax({
				url: 'http://113.71.26.27:8080/tpl/function/insertcomment',
				async: true,
				type: 'post',
				data: {
					topic_id: topic_id,
					from_id: from_id,
					to_id: to_id,
					content: content
				},
				success: function(data) {
					share111();
				}
			});
		}
		
		
		
		
		//验证是否是员工
		function checkWho() {
			
			
				var network=true;
				if(mui.os.plus) {
							mui.plusReady(function() {
								if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
									network = false;
								}
							});
						}
				if(network){
				
					mui.ajax({
						url:"http://113.71.26.27:8080/tpl/share1/checkWho",
						async:true,
						type: 'post',
						data:{
							loginName:loginName
						},
						success:function(data) {
							
						 //加入企业
							if(data=="true"){
								
								share111();
							
							
							}else{
								
								var shareData="<center style='color:blue;' class='center'>你还没加入企业</center>";
								document.getElementById("share").innerHTML = shareData;
								$('#menu').attr('href','#');
								
						 
							}
						},
						error: function(xhr, type, errorThrown) {
									plus.nativeUI.toast(errorThrown);
								}
					});
				}else{
					mui.toast("当前网络不给力，请稍后再试...");
				}

		}
	</script>

</html>